package demo;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
  
  
public class WaitForSomthing {  
	  static WebElement element =null;
    public static void main(String[] args) {  

      //  System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");    
        WebDriver dr = new FirefoxDriver();  
        String url = "file:///C:/Users/wangyang05/Desktop/wait.html";
        dr.get(url);  
        WebDriverWait wait = new WebDriverWait(dr,10);  
        wait.until(new ExpectedCondition<WebElement>(){  
            @Override  
            public WebElement apply(WebDriver d) {  
                return d.findElement(By.id("b"));  
            }}).click();  
          //wait 5 seconds then the red box will be showed
         
        WebDriverWait waitforred = new WebDriverWait(dr,6);
        waitforred.until(new ExpectedCondition<WebElement>(){
			@Override
			public WebElement apply(WebDriver d) {
               return element = d.findElement(By.className("red_box"));
			}	
        });
//        dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//        element = dr.findElement(By.className("red_box"));
    
        ((JavascriptExecutor)dr).executeScript("arguments[0].style.border = \"5px solid yellow\"",element);    
     
        
        dr.close();
          
    }  
}  